﻿using AutoRegistDependency.Abstract;
using AutoRegistDependency.Attributes;
using Castle.DynamicProxy;
using System.Reflection;
using WebTest.Bean;
using WebTest.Services.Test;

namespace WebTest.Interceptor
{
	[Component]
	public class TestInterceptor : AbstractInterceptor
    {
		
        private ITest test;

		public TestInterceptor([ComponentFilter(Name ="test2")] ITest test)
		{
			this.test = test;
		}

		public override IEnumerable<Type> GetInterceptorTypes(IEnumerable<Assembly> dll)
		{
			return new Type[] { typeof(Test)};
		}

		public override void InterceptAsynchronous(IInvocation invocation)
		{
			Console.WriteLine($"before:{nameof(InterceptAsynchronous)}");
            invocation.Proceed();
			Console.WriteLine($"after:{nameof(InterceptAsynchronous)}");
		}

		public override void InterceptAsynchronous<TResult>(IInvocation invocation)
		{
			Console.WriteLine($"before:{nameof(InterceptAsynchronous)}");
			invocation.Proceed();
			Console.WriteLine($"after:{nameof(InterceptAsynchronous)}");
		}

		public override void InterceptSynchronous(IInvocation invocation)
		{
			Console.WriteLine($"before:{nameof(InterceptSynchronous)}");
            test.Say();
            invocation.Proceed();
			Console.WriteLine($"after:{nameof(InterceptSynchronous)}");
		}
	}
}
